package com.tau.egonetwork.gui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Monitor;
import org.eclipse.swt.widgets.Shell;

import com.tau.egonetwork.common.Log;

public class AboutDialog extends Dialog {

	public AboutDialog(Shell parent) {
		super(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
	}

	public void open() {
		
		Shell shell = new Shell(getParent(), getStyle());
		shell.setText("About");
		
		populate(shell);
		
		shell.pack();
		
		//set shell at the center of display:
	    Monitor primary = getParent().getMonitor();
	    Rectangle bounds = primary.getBounds();
	    Rectangle rect = shell.getBounds();
	    int x = bounds.x + (bounds.width - rect.width) / 2;
	    int y = bounds.y + (bounds.height - rect.height) / 2;
	    shell.setLocation(x, y);
		
		Log.writeLineToLog("opening dialog");

		shell.open();
		
		//keep shell open, waiting for user input:
		Display display = getParent().getDisplay();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
	}

	private void populate(Shell shell) {
		
		GridLayout layout = new GridLayout(1, false);
		layout.marginRight = 40;
		layout.marginLeft = 40;
		layout.marginTop = 15;
		layout.marginBottom = 20;
		shell.setLayout(layout);
		shell.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
		
        Font regularFont = new Font(shell.getDisplay(), "Ariel", 11, SWT.NORMAL);
        Font boldFont = new Font(shell.getDisplay(), "Ariel", 11, SWT.BOLD);
        Font titleFont = new Font(shell.getDisplay(), "Tahoma", 18, SWT.BOLD);
        Font subtitleFont = new Font(shell.getDisplay(), "Tahoma", 14, SWT.BOLD);        

        Label title = new Label(shell, SWT.NONE);
        title.setText("Egocenteric Networks");
        title.setFont(titleFont);
        title.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false));
        
        Label subtitle = new Label(shell, SWT.NONE);
        subtitle.setText("Faculty of Engeneering");
        subtitle.setFont(subtitleFont);
        subtitle.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false));
		
        Label subtitle2 = new Label(shell, SWT.NONE);
        subtitle2.setText("Final Project, 2013-2014");
        subtitle2.setFont(boldFont);
        subtitle2.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false));
        
        {
    		Composite separatorComposite = new Composite(shell, SWT.NONE);
    		GridLayout separatorCompositeGridLayout = new GridLayout(1, true);
    		separatorCompositeGridLayout.marginWidth = 0;
    		separatorCompositeGridLayout.marginLeft = 0;
    		separatorCompositeGridLayout.marginRight = 0;
    		separatorComposite.setLayout(separatorCompositeGridLayout);
    		separatorComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    		
    		Label separator = new Label(separatorComposite, SWT.SEPARATOR | SWT.HORIZONTAL);
    		separator.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
        }
        
        Label guyEngel = new Label(shell, SWT.NONE);
        guyEngel.setText("Guy Engel");
        guyEngel.setFont(regularFont);
        guyEngel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false));

        Label oriLentzitzky = new Label(shell, SWT.NONE);
        oriLentzitzky.setText("Ori Lentzitzky");
        oriLentzitzky.setFont(regularFont);
        oriLentzitzky.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false));

        {
    		Composite separatorComposite = new Composite(shell, SWT.NONE);
    		GridLayout separatorCompositeGridLayout = new GridLayout(1, true);
    		separatorCompositeGridLayout.marginWidth = 0;
    		separatorCompositeGridLayout.marginLeft = 0;
    		separatorCompositeGridLayout.marginRight = 0;
    		separatorComposite.setLayout(separatorCompositeGridLayout);
    		separatorComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    		
    		Label separator = new Label(separatorComposite, SWT.SEPARATOR | SWT.HORIZONTAL);
    		separator.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
        }
        
        Label leaders = new Label(shell, SWT.NONE);
        leaders.setText("Project Leaders:");
        leaders.setFont(boldFont);
        leaders.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false));
        
        Label efratBlumenfeld = new Label(shell, SWT.NONE);
        efratBlumenfeld.setText("Efrat Blumenfeld-Lieberthal");
        efratBlumenfeld.setFont(regularFont);
        efratBlumenfeld.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false));

        Label odedBarzely = new Label(shell, SWT.NONE);
        odedBarzely.setText("Oded Barzely");
        odedBarzely.setFont(regularFont);
        odedBarzely.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false));
        
        {
    		Composite separatorComposite = new Composite(shell, SWT.NONE);
    		GridLayout separatorCompositeGridLayout = new GridLayout(1, true);
    		separatorCompositeGridLayout.marginWidth = 0;
    		separatorCompositeGridLayout.marginLeft = 0;
    		separatorCompositeGridLayout.marginRight = 0;
    		separatorComposite.setLayout(separatorCompositeGridLayout);
    		separatorComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    		
    		Label separator = new Label(separatorComposite, SWT.SEPARATOR | SWT.HORIZONTAL);
    		separator.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
        }
    
        Label iconsLabel = new Label(shell, SWT.NONE);
        iconsLabel.setText("Icons courtesy of www.freeicons.com (for non-commerical use)");
        iconsLabel.setFont(regularFont);
        iconsLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false));

	}
}
